home *** CD-ROM | disk | FTP | other *** search
- /*
- #-------------------------------------------------------------------------------------------
- #
- # Program: < DMZ 1.3 >
- # File: < dmzLists.c >
- #
- # by pvh
- # of <Apple Macintosh Developer Technical Support - or wheverever>
- #
- # Modification History
- # 5/27/94 rrk Made PPC compatible
- # 9/21/92 rrk Got rid of "^2 ^3" string left in dialog at init time
- # if DMZ started on system with no zones. Put in paramText
- # call in tellUserNoZones()
- #
- # Copyright © 1990 Apple Computer, Inc.
- # All rights reserved.
- #
- #-------------------------------------------------------------------------------------------
- */
-
- #include "dmz.h"
-
- /*
- * External globals we use in this dude.
- */
- extern DialogPtr gMyDialog;
- extern long gSortMode;
- extern EventRecord gMyEvent;
- extern short gATalkTransFlag;
- extern myATQEntry gATQEntry;
- /*
- * Globals we use here
- */
- ListHandle gZonesList, gObjectTypeList;
- char gNameGlob[33];
-
-
- /*
- * This is a simple routine that invalidates the passed in dialog item's rectangle
- * so that we get a cleaner refresh of only the items that need updating.
- */
- void invalidateItem(short whichItem)
- {
- Rect r;
- short kind;
- Handle h;
- GrafPtr savedPort;
-
- GetPort(&savedPort);
- SetPort(gMyDialog);
- GetDItem(gMyDialog, whichItem, &kind, &h, &r);
- InvalRect(&r);
- BeginUpdate(gMyDialog);
- UpdtDialog(gMyDialog, gMyDialog->visRgn);
- EndUpdate(gMyDialog);
- SetPort(savedPort);
- }
-
-
- void DisposOfMyLists()
- {
- LDispose(gZonesList);
- LDispose(gObjectTypeList);
- }
-
- void OpenZonesList()
- {
- Rect dBounds, rView;
- Point cSize;
- GrafPtr tp;
- short kind;
- Handle h;
-
- GetPort(&tp);
- SetPort(gMyDialog);
- GetDItem(gMyDialog, 1, &kind, &h, &rView);
-
- rView.top += 1;
- rView.bottom -= 1;
- rView.right -= 16;
-
- cSize.v = 0;
- cSize.h = 0;
-
- SetRect(&dBounds, 0, 0, 1, 0);
- gZonesList = LNew(&rView, &dBounds, cSize, 0, gMyDialog, true, false, false, true);
- (**gZonesList).selFlags = lUseSense+lOnlyOne;
- SetPort(tp);
- }
-
- void tellUserNoZones()
- {
- Cell theCell;
- short ignore, i;
- GrafPtr tp;
-
- ClearZoneCells(); // quick way to clear out an old entry - sort of overkill
- GetPort(&tp);
- SetPort(gMyDialog);
-
- LDoDraw(false, gZonesList);
-
- i = 0;
-
- theCell.v = i;
- theCell.h = 0;
-
- ignore = LAddRow(1, i, gZonesList);
-
- LClrCell(theCell, gZonesList);
- if (((dmzEntryPtr) *(gATQEntry.globs))->atalkActive) // If ATalk active.
- {
- LSetCell("No zones <*>.", PStrLen("\pNo zones <*>."), theCell, gZonesList);
- ParamText("\p", "\p", "\p", "\p");
- }
- else
- {
- LSetCell("AppleTalk is off.", PStrLen("\pAppleTalk is off."), theCell, gZonesList);
- ParamText("\p", "\p", "\p", "\p");
- }
-
- LDoDraw(true, gZonesList);
- InvalRect(&(**gZonesList).rView);
- SetPort(tp);
- }
-
- /*****************************************************************************/
-
-
-
- /* Compare two pascal-strings. */
-
- #pragma segment StringUtils
- short pcmp(StringPtr s1, StringPtr s2)
- {
- short i, len;
- char j;
-
- if ((len = s1[0]) > s2[0]) len = s2[0];
-
- for (i = 1; i <= len; ++i)
- if (j = s1[i] - s2[i]) return(j);
-
- return(s1[0] - s2[0]);
- }
-
-
- /*
- * compare routine for qsort(). it uses a global selector for the different 'fields' inthe list
- * they are actually offsets to the data in each cell.
- * OK...so it's really gross.
- */
- int myCompare(char *aStr, char *bStr)
- {
- long sortPtr;
-
- switch(gSortMode) {
- case sortOnZoneName:
- sortPtr = myNetworkEntityObject;
- break;
- case sortOnType:
- sortPtr = myNetworkEntityType;
- break;
- case sortOnNet:
- sortPtr = myNetworkEntityNet;
- break;
- case sortOnNode:
- sortPtr = myNetworkEntityNode;
- break;
- case sortOnSocket:
- sortPtr = myNetworkEntitySocket;
- break;
- }
- return(IUCompString((void *)(aStr + sortPtr), (void *)(bStr + sortPtr)));
- }
-
- /*
- * call qsort()
- */
- void letsSort(Ptr theBuffPtr, short numZonesGot, short number)
- {
- SetPort(gMyDialog);
-
- /* tell them we're sorting */
- ParamText("\p", "\p", "\p", "\psorting...");
- invalidateItem(kProgressID);
-
- /* do the sort */
- qsort(theBuffPtr, (unsigned long)numZonesGot, (unsigned long)number, myCompare);
-
- /* erase the info text */
- ParamText("\p", "\p", "\p", "\p");
- invalidateItem(kProgressID);
- }
-
-
- /*
- * set up the zone list
- */
- void SetZoneCells(Ptr bufferPtr, short NumZonesGot)
- {
- Cell theCell;
- short ignore, i;
- long bufferIndex;
- GrafPtr tp;
- Str32 myZone, zoneString;
-
- #ifndef powerc
- MYVBLSPININSTALL();
- #endif
-
- myZone[0] = 0;
- getMyZone((char *)myZone);
-
- GetPort(&tp);
- SetPort(gMyDialog);
-
- /* added 5/5/89 pvh */
- gSortMode = sortOnZoneName;
- letsSort(bufferPtr, NumZonesGot, zoneNameSize);
-
- LDoDraw(false, gZonesList);
-
- bufferIndex = 0L;
- i = 0;
- while(i<NumZonesGot) {
- ignore = LAddRow(1, i, gZonesList);
- theCell.v = i;
- theCell.h = 0;
-
- zoneString[0] = (char)(bufferPtr+bufferIndex)[0];
- LSetCell((Ptr)bufferPtr+bufferIndex + 1L, zoneString[0], theCell, gZonesList);
-
- /*
- * when we find our zone, select it in the list
- */
- zoneString[0] = (char)(bufferPtr+bufferIndex)[0];
- BlockMove((Ptr)bufferPtr+bufferIndex + 1L, (Ptr)&zoneString + 1L, zoneString[0]);
- if(EqualString(zoneString, myZone, false, false)) {
- LSetSelect(true, theCell, gZonesList);
- LAutoScroll(gZonesList);
- getTypesNamesInZone((char *)zoneString);
- }
-
- i += 1;
- bufferIndex += zoneNameSize;
- }
-
- LDoDraw(true, gZonesList);
-
- SetPort(tp);
-
- #ifndef powerc
- STOPANDREMOVESPINNINGCURSOR();
- #endif
- }
-
- /*
- * clear the zone list
- */
- void ClearZoneCells()
- {
- GrafPtr tp;
- Str32 tempStr;
-
- #ifndef powerc
- MYVBLSPININSTALL();
- #endif
-
- GetPort(&tp);
- SetPort(gMyDialog);
-
- ParamText("\p", "\p", "\p", "\p"); // clear the number of items text which appears in item 7
-
- // clear out the "number of found items" dialog item
- tempStr[0] = 0;
- setItemString(gMyDialog, (short) kObjectCountID, tempStr);
-
- LDoDraw(false, gZonesList);
-
- LDelRow(0,0, gZonesList);
- EraseRect(&(**gZonesList).rView);
-
- LDoDraw(true, gZonesList);
- InvalRect(&(**gZonesList).rView);
-
- SetPort(tp);
-
- #ifndef powerc
- STOPANDREMOVESPINNINGCURSOR();
- #endif
- }
-
- /*
- * handle click in the zone list box
- */
- void doZonesListStuff()
- {
- Boolean tempBool;
- Cell thisCell;
- Rect scrollRect;
- GrafPtr tp;
- Str255 dataPtr;
- short dataLen;
- Point localPoint = gMyEvent.where;
-
- thisCell.v = 0;
- thisCell.h = 0;
- GetPort(&tp);
- SetPort(gMyDialog);
-
- if(gMyDialog != FrontWindow())
- SelectWindow(gMyDialog);
- else
- {
- if (!((dmzEntryPtr) *(gATQEntry.globs))->atalkActive) // ATalk not active.
- return;
- GlobalToLocal(&localPoint);
- scrollRect = (**gZonesList).rView;
- scrollRect.left = (**gZonesList).rView.right;
- scrollRect.right = scrollRect.left + 15;
- if(PtInRect(localPoint, &scrollRect))
- tempBool = LClick(localPoint, gMyEvent.modifiers, gZonesList);
- else if(PtInRect(localPoint, &(**gZonesList).rView)) {
- if(LClick(localPoint, gMyEvent.modifiers, gZonesList)) {
- LGetSelect(true, &thisCell, gZonesList);
- dataLen = 255;
- LGetCell(&dataPtr[1], &dataLen, thisCell, gZonesList);
- dataPtr[0] = dataLen;
- BlockMove(&dataPtr, &gNameGlob[0], 34L);
- getTypesNamesInZone((char *)dataPtr);
- }
- else {
- LGetSelect(true, &thisCell, gZonesList);
- dataLen = 255;
- LGetCell(&dataPtr[1], &dataLen, thisCell, gZonesList);
-
- dataPtr[0] = dataLen;
-
- BlockMove(&dataPtr[0], &gNameGlob[0], 34L);
- }
- }
- }
- SetPort(tp);
- }
-
- void OpenObjectTypeList()
- {
- Rect dBounds, rView;
- Point cSize;
- GrafPtr tp;
- Handle h;
- short kind, ignore;
-
- GetPort(&tp);
- SetPort(gMyDialog);
- GetDItem(gMyDialog, 2, &kind, &h, &rView);
-
- rView.top += 1;
- /*
- // rView.bottom -= 1;
- // rView.bottom = gMyDialog->portRect.bottom-16;
- */
-
- rView.right -= 16;
-
- cSize.v = 0;
- cSize.h = 0;
-
- SetRect(&dBounds, 0, 0, 1, 0); /* two cells across by 0 down extra cell for hiding entity net address */
- gObjectTypeList = LNew(&rView, &dBounds, cSize, 128, gMyDialog, true, false, false, true);
- (**gObjectTypeList).selFlags = lUseSense+lOnlyOne;
-
- SizeControl((**gObjectTypeList).vScroll, (**(**gObjectTypeList).vScroll).contrlRect.right -
- (**(**gObjectTypeList).vScroll).contrlRect.left, (**(**gObjectTypeList).vScroll).contrlRect.bottom -
- (**(**gObjectTypeList).vScroll).contrlRect.top - 16);
-
- ignore = LAddColumn(1, 0, gObjectTypeList);
-
- SetPort(tp);
- }
-
- void doObjectDoubleClick()
- {
- Cell thisCell;
- short dataLen;
- long temp;
- myNetworkEntity myEnt;
- AddrBlock address;
-
- thisCell.v = 0;
- thisCell.h = 0;
- LGetSelect(true, &thisCell, gObjectTypeList);
-
- /*
- * at this point do whatever you want with the object selection.
- * send 'em lots of packets and try and kill them or whatever...
- */
- dataLen = sizeof(myNetworkEntity);
- LGetCell((Ptr) &myEnt, &dataLen, thisCell, gObjectTypeList);
-
- StringToNum((void *) myEnt.net, (long *) &temp);
- address.aNet = (short) temp;
- StringToNum((void *) myEnt.node, (long *) &temp);
- address.aNode = (short) temp;
- StringToNum((void *) myEnt.socket, (long *) &temp);
- address.aSocket = (short) temp;
- doEcho(&myEnt);
- }
-
-
- void doObjectTypeListStuff()
- {
- Boolean ignore;
- Cell thisCell;
- Rect scrollRect;
- GrafPtr tp;
- Point localPoint = gMyEvent.where;
-
- thisCell.v = 0;
- thisCell.h = 0;
- GetPort(&tp);
- SetPort(gMyDialog);
-
- if(gMyDialog != FrontWindow())
- SelectWindow(gMyDialog);
- else {
- if (!((dmzEntryPtr) *(gATQEntry.globs))->atalkActive) // ATalk not active.
- return;
- GlobalToLocal(&localPoint);
- scrollRect = (**gObjectTypeList).rView;
- scrollRect.left = (**gObjectTypeList).rView.right;
- scrollRect.right = scrollRect.left + 15;
- if(PtInRect(localPoint, &scrollRect))
- ignore = LClick(localPoint, gMyEvent.modifiers, gObjectTypeList);
- else if(PtInRect(localPoint, &(**gObjectTypeList).rView)) {
- /*
- * Check for a double click.
- */
- if(LClick(localPoint, gMyEvent.modifiers, gObjectTypeList)) {
- doObjectDoubleClick();
- }
- }
- }
- SetPort(tp);
- }
-
- /*
- * clear the object and types list
- */
- void ClearObjectTypesList()
- {
- GrafPtr tp;
-
- #ifndef powerc
- MYVBLSPININSTALL();
- #endif
-
- GetPort(&tp);
- SetPort(gMyDialog);
-
- LDoDraw(false, gObjectTypeList);
-
- LDelRow(0,0, gObjectTypeList);
- EraseRect(&(**gObjectTypeList).rView);
-
- LDoDraw(true, gObjectTypeList);
- InvalRect(&(**gObjectTypeList).rView);
-
- SetPort(tp);
-
- #ifndef powerc
- STOPANDREMOVESPINNINGCURSOR();
- #endif
- }
-
- /*
- * this routine pads strings out to various lengths. justification to right or left can
- * be specified. we need this for a cleaner display as well as insuring a correct sort
- * on numeric data (i.e. the strings '1234' and ' 1234' are not equivalant, but if
- * we justify to the right, we'll always be OK. (whoops maybe not in the case of the Japanese
- * alphabet...damn...
- */
- void padEntry(unsigned char *entry, short length, short just)
- {
- unsigned char index, i;
-
- switch(just) {
- case leftJust:
- index = entry[0]; /* get length byte */
- index += 1; /* increment by 1 */
-
- while(index <= length) {
- entry[index] = ' ';
- index += 1;
- }
- break;
- case rightJust:
- index = entry[0]; /* get length byte */
-
- if(index<length) {
- BlockMove(&entry[1], (Ptr)&entry[1]+length-index, (long)index);
-
- i = 1;
- while(index < length) {
- entry[i] = ' ';
- i += 1;
- index += 1;
- }
- }
- break;
- }
- entry[0] = length;
- }
-
- /*
- * this is called when the NBPLookup has finished. the buffer and the number of obects found
- * is added to the list.
- */
- void SetObjectTypeCells(Ptr bufferPtr, short numDevicesGot)
- {
- Cell theCell;
- short ignore;
- short numDevicesIndex;
- GrafPtr tp;
- AddrBlock address;
- EntityName abEntity;
- unsigned char charHolder[6];
- long g;
- myNetworkEntity myNetEnt;
- Ptr newBuffer;
- char tempStr[10];
-
- /* tell the user this may take a little while... */
- /*waitAWhile = GetCursor(watchCursor);
- SetCursor(*waitAWhile);*/
-
- #ifndef powerc
- MYVBLSPININSTALL();
- #endif
-
- GetPort(&tp);
- SetPort(gMyDialog);
-
- /* make room for as many objects as we need */
- newBuffer = NewPtr(numDevicesGot*sizeof(myNetworkEntity));
- if(newBuffer == 0L)
- return;
-
- LDelRow(0, 0, gObjectTypeList); /* deletes lists's cells */
-
- LDoDraw(false, gObjectTypeList); /* turn drawing off */
-
- numDevicesIndex = 0;
-
- while(numDevicesIndex<numDevicesGot) {
- theCell.v = numDevicesIndex;
-
- ignore = LAddRow(1, numDevicesIndex, gObjectTypeList);
-
- NBPExtract(bufferPtr, numDevicesGot, numDevicesIndex+1, &abEntity, &address);
-
- /* first move address data into "hidden" cell */
- theCell.h = 1;
- LSetCell((Ptr) &address, 4, theCell, gObjectTypeList);
-
- /* now move object name & type into one cell */
- theCell.h = 0;
-
- /* object */
- BlockMove(&abEntity.objStr, &myNetEnt.object, 33L);
- if(myNetEnt.object[0] > 32)
- myNetEnt.object[0] = 32;
-
- /* type */
- BlockMove(&abEntity.typeStr, &myNetEnt.type, 33L);
- if(myNetEnt.type[0] > 32)
- myNetEnt.type[0] = 32;
-
- /* network */
- g = (long)address.aNet;
- g = g & 0x0000FFFF; /* mask out hiword crap */
- NumToString(g, (void *) &charHolder);
- padEntry((void *) &charHolder, 5, rightJust);
- BlockMove(&charHolder, &myNetEnt.net, 6L);
-
- /* node */
- NumToString((long)address.aNode, (void *) &charHolder);
- padEntry((void *) &charHolder, 3, rightJust);
- BlockMove(&charHolder, &myNetEnt.node, 4L);
-
- /* socket */
- NumToString((long)address.aSocket, (void *) &charHolder);
- padEntry((void *) &charHolder, 3, rightJust);
- BlockMove(&charHolder, &myNetEnt.socket, 4L);
-
- BlockMove((Ptr) &myNetEnt, (Ptr)newBuffer+(numDevicesIndex)*sizeof(myNetworkEntity),
- sizeof(myNetworkEntity));
-
- LSetCell((Ptr)&myNetEnt, sizeof(myNetworkEntity), theCell, gObjectTypeList);
-
- numDevicesIndex += 1;
- }
-
- /* do a quicksort() on the mess */
- letsSort(newBuffer, numDevicesGot, sizeof(myNetworkEntity));
-
- numDevicesIndex = 0;
-
- while(numDevicesIndex<numDevicesGot) {
- theCell.v = numDevicesIndex;
- theCell.h = 0;
- BlockMove((Ptr)newBuffer+(numDevicesIndex)*sizeof(myNetworkEntity), (Ptr) &myNetEnt, sizeof(myNetworkEntity));
- LSetCell((Ptr)&myNetEnt, sizeof(myNetworkEntity), theCell, gObjectTypeList);
- numDevicesIndex += 1;
- }
-
- DisposPtr(newBuffer);
-
- NumToString(numDevicesIndex, (void *) tempStr);
- ParamText((ConstStr255Param)tempStr, "\p# of objects: ", "\p", "\p");
-
- LDoDraw(true, gObjectTypeList);
- invalidateItem(8);
- invalidateItem(2);
-
- SetPort(tp);
- #ifndef powerc
- STOPANDREMOVESPINNINGCURSOR();
- #endif
- InitCursor();
- }
-
-
-